/**
 * Created by tms on 17/11/7.
 * arcgis 精灵类:id,宽，高，经纬度，帧频,起始帧是否随机？
 */

var EsGraphicSpriteHelper=new Object();

EsGraphicSpriteHelper.initSymls = function (picArr,Width,Height) {

    var myLen = picArr.length;
    var sybmblArr = new Array();
    for (var i = 0; i < myLen; i++) {
        //加入一个一个的symbol
        var symbolItem = tmsMap.PictureMarkerSymbol({
            url: picArr[i],
            width: Width+"px",
            height:Height+"px"
        });

        sybmblArr.push(symbolItem);

    }

   return sybmblArr;



}


function EsGraphicSprite(id, lng, lat,  symbolArr,frameRate, isRnd,GroupKey,typeKey) {


    this.Id = id;


    this.frameRate = frameRate;
    this.isRnd = isRnd;

    this.point = new tmsMap.Point({
        latitude: lat,
        longitude: lng

    });



    //动画属性


    this.sybmblArr = new Array();
    this.iIndex = 0;//当前播放序列的索引号
    this.oldObject = null;

    //帧动画数量
    this.sybmblCounter = symbolArr.length;


    //初始化动画符号
    this.sybmblArr=symbolArr;



    this.iIndex=Math.floor(Math.random()*this.sybmblArr.length);

    this.typeKey=typeKey;//类型key,方便删除或处理
    this.GroupKey=GroupKey;//分组key,方便删除或处理

}




//
// //初始化对应的动画数组对象
// EsGraphicSprite.prototype.initSymls = function (picArr) {
//
//     var myLen = picArr.length;
//     this.sybmblArr = [];
//     for (var i = 0; i < myLen; i++) {
//         //加入一个一个的symbol
//         var symbolItem = tmsMap.PictureMarkerSymbol({
//             url: picArr[i],
//             width: this.Width+"px",
//             height: this.Height+"px"
//         });
//
//         this.sybmblArr.push(symbolItem);
//
//     }
//
//     this.sybmblCounter = myLen;
//
//
//
//
// }
//动画方法

EsGraphicSprite.prototype.Animate = function (counter) {

    if (counter % this.frameRate == 0) {
        //在指定的帧频内，则执行

        //console.log("执行Sprite ID:" + this.Id);


        var newObj = new tmsMap.Graphic({
            geometry: this.point,
            symbol: this.sybmblArr[this.iIndex]
        })
        //console.log('animate...' + this.iIndex);
        if (this.oldObject != null)
            tmsMap.animateLayer.remove(this.oldObject);
        tmsMap.animateLayer.add(newObj);
        this.oldObject = newObj;
        this.iIndex++;
        this.iIndex=this.iIndex%this.sybmblCounter;
    }

}
